<template>
  <div class="customerOrder">
    <el-form
      ref="form"
      :model="form"
      label-width="80px"
      size="mini"
      class="demo-ruleForm"
      style="display: flex; flex-wrap: wrap"
    >
      <el-form-item label="订单号">
        <el-input v-model="form.orderNumber"></el-input>
      </el-form-item>
      <!-- <el-form-item label="会员卡号">
        <el-input v-model="form.cardCode"></el-input>
      </el-form-item> -->
      <el-form-item label="手机号">
        <el-input v-model="form.cardHolderPhone"></el-input>
      </el-form-item>
      <el-form-item label="支付状态">
        <el-select clearable v-model="form.payStatus" placeholder="请选择">
          <el-option label="待支付" value="unpaid"></el-option>
          <el-option label="已支付" value="haspay"></el-option>
          <el-option label="取消支付" value="cancelpay"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="支付方式">
        <el-select clearable v-model="form.payType" placeholder="请选择">
          <el-option label="信用卡" value="creditcard"></el-option>
          <el-option label="借记卡" value="debitcard"></el-option>
          <el-option label="支付宝" value="aliPay"></el-option>
          <el-option label="微信" value="wechatPay"></el-option>
          <el-option label="总办送卡" value="giveAway"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="创建时间">
        <el-date-picker
          size="mini"
          style="width: 140px"
          v-model="form.createDateMin"
          type="date"
          placeholder="选择日期"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="----">
        <el-date-picker
          size="mini"
          style="width: 140px"
          v-model="form.createDateMax"
          type="date"
          placeholder="选择日期"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="会员卡号">
        <el-input v-model="form.vipCardNumber"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="mini" @click="query">查询</el-button>
      </el-form-item>
      <!-- <el-form-item>
        <download-excel class="blueBtn" :data="recordsData" :fields="json_fields" worksheet="My Worksheet" name="会员卡订单">
          导出
        </download-excel>
      </el-form-item> -->
    </el-form>
    <!-- 表格 -->
    <el-table
      border
      :data="recordsData"
      size="mini"
      :header-cell-style="{
        color: '#fff',
        background: '#6090EC',
        fontSize: '11px',
        fontWeight: 'normal',
        width: '1300px',
      }"
      style="width: 100%"
    >
      <el-table-column prop="orderNumber" label="订单号" width="80">
      </el-table-column>
      <el-table-column prop="cardHolderName" label="会员名称" width="80">
      </el-table-column>
      <el-table-column prop="cardName" label="卡名称" width="80">
      </el-table-column>
      <el-table-column prop="vipCardNumber" label="卡号" width="80">
      </el-table-column>
      <el-table-column prop="isPackage" label="购买年限" width="80">
        <template slot-scope="scope">
          <template v-if="scope.row.isPackage == 'no'">一年</template>
          <template v-if="scope.row.isPackage == 'yes'">两年</template>
        </template>
      </el-table-column>
      <el-table-column prop="totalAmount" label="订单金额" width="80">
      </el-table-column>
      <el-table-column prop="actualPayAmount" label="实际支付金额" width="120">
      </el-table-column>
      <el-table-column prop="goldAmount" label="金币" width="80">
      </el-table-column>
      <el-table-column prop="reserveAmount" label="预留款" width="80">
      </el-table-column>
      <el-table-column prop="integralAmount" label="积分" width="80">
      </el-table-column>
      <el-table-column prop="couponAmount" label="优惠卷" width="80">
      </el-table-column>
      <el-table-column prop="createTime" label="订单创建时间" width="120">
      </el-table-column>
      <el-table-column prop="adminName" label="订单创建人" width="120">
      </el-table-column>
      <el-table-column prop="payType" label="支付方式" width="90">
        <template slot-scope="scope">
          <template v-if="scope.row.payType == 'creditcard'">信用卡</template>
          <template v-if="scope.row.payType == 'debitcard'">借记卡</template>
          <template v-if="scope.row.payType == 'aliPay'">支付宝</template>
          <template v-if="scope.row.payType == 'wechatPay'">微信</template>
          <template v-if="scope.row.payType == 'giveAway'">总办送卡</template>
          <template v-if="scope.row.payType == 'unionPayQrCode'">银联二维码</template>
        </template>
      </el-table-column>
      <el-table-column prop="payStatus" label="支付状态" width="80">
        <template slot-scope="scope">
          <template v-if="scope.row.payStatus == 'unpaid'">待支付</template>
          <template v-if="scope.row.payStatus == 'haspay'">已支付</template>
          <template v-if="scope.row.payStatus == 'cancelpay'"
            >取消支付</template
          >
        </template>
      </el-table-column>
      <el-table-column prop="orderSource" label="订单来源" width="80">
        <template slot-scope="scope">
          <template v-if="scope.row.orderSource == 'crm'">crm</template>
          <template v-if="scope.row.orderSource == 'program'">小程序</template>
          <template v-if="scope.row.orderSource == 'android'">安卓</template>
          <template v-if="scope.row.orderSource == 'ios'">苹果</template>
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" width="170">
        <template slot-scope="scope">
          <!-- <el-button v-if="scope.row.state=='cancelPay'" size="mini" type="primary" @click="gopay(scope.row)">去支付</el-button> -->
          <el-button size="mini" type="primary" @click="details(scope.row)"
            >详情</el-button
          >
          <el-button
            size="mini"
            type="primary"
            v-if="
              scope.row.payStatus == 'haspay' && scope.row.payType != 'giveAway'
            "
            @click="billdrawBtn(scope.row)"
            >补开发票</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[10, 15, 20]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageTotal"
    >
    </el-pagination>
    <!-- 详情页弹窗 -->
    <el-dialog
      title="会员卡订单详情"
      :visible.sync="centerDialogVisible"
      :close-on-click-modal="false"
      width="60%"
      center
    >
      <div>
        <el-row>
          <el-col :span="3"
            ><div class="grid-content bg-purple">会员姓名：</div></el-col
          >
          <el-col :span="5"
            ><div class="grid-content bg-purple-light">
              {{
                orderDetilData.cardHolderName
                  ? orderDetilData.cardHolderName
                  : "-"
              }}
            </div></el-col
          >
          <el-col :span="3"
            ><div class="grid-content bg-purple">会员手机号：</div></el-col
          >
          <el-col :span="5"
            ><div class="grid-content bg-purple-light">
              {{
                orderDetilData.cardHolderPhone
                  ? orderDetilData.cardHolderPhone
                  : "-"
              }}
            </div></el-col
          >
          <el-col :span="3"
            ><div class="grid-content bg-purple">会员证件：</div></el-col
          >
          <el-col :span="5"
            ><div class="grid-content bg-purple-light">
              {{
                orderDetilData.cardHolderIdType == "ZGJMSFZ"
                  ? "身份证"
                  : orderDetilData.cardHolderIdType == "HKB"
                  ? "户口薄"
                  : orderDetilData.cardHolderIdType == "WGRYJJLSFZ"
                  ? "外国人永久居留身份证"
                  : orderDetilData.cardHolderIdType == "GATJMJZZ"
                  ? "港澳台居民居住证"
                  : orderDetilData.cardHolderIdType == "GAJMLWNDTXZ"
                  ? "港澳居民来往内地通行证"
                  : orderDetilData.cardHolderIdType == "TWJMLWDLTXZ"
                  ? "台湾居民来往大陆通行证"
                  : orderDetilData.cardHolderIdType == "HZ"
                  ? "护照"
                  : orderDetilData.cardHolderIdType == "MILITARY"
                  ? "军人证"
                  : orderDetilData.cardHolderIdType == "BIRTH"
                  ? "出生证明"
                  : "-"
              }}
            </div></el-col
          >
        </el-row>
        <el-row>
          <el-col :span="3"
            ><div class="grid-content bg-purple">会员证件号：</div></el-col
          >
          <el-col :span="5"
            ><div class="grid-content bg-purple-light">
              {{
                orderDetilData.cardHolderIdNumber
                  ? orderDetilData.cardHolderIdNumber
                  : "-"
              }}
            </div></el-col
          >
        </el-row>
        <el-row>
          <el-col :span="3"
            ><div class="grid-content bg-purple">订单号：</div></el-col
          >
          <el-col :span="5"
            ><div class="grid-content bg-purple-light">
              {{
                orderDetilData.orderNumber ? orderDetilData.orderNumber : "-"
              }}
            </div></el-col
          >
          <el-col :span="3"
            ><div class="grid-content bg-purple">订单金额：</div></el-col
          >
          <el-col :span="5"
            ><div class="grid-content bg-purple-light">
              {{
                orderDetilData.totalAmount ? orderDetilData.totalAmount : "-"
              }}
            </div></el-col
          >
          <el-col :span="3"
            ><div class="grid-content bg-purple">卡单价：</div></el-col
          >
          <el-col :span="5"
            ><div class="grid-content bg-purple-light">
              {{ orderDetilData.cardAmount ? orderDetilData.cardAmount : "-" }}
            </div></el-col
          >
        </el-row>
        <el-row>
          <el-col :span="3"
            ><div class="grid-content bg-purple">是否连续包年：</div></el-col
          >
          <el-col :span="5"
            ><div class="grid-content bg-purple-light">
              {{ orderDetilData.isPackage == "yes" ? "是" : "否" }}
            </div></el-col
          >
          <el-col :span="3"
            ><div class="grid-content bg-purple">订单类型：</div></el-col
          >
          <el-col :span="5"
            ><div class="grid-content bg-purple-light">
              {{ orderDetilData.orderType == "renewal" ? "续费" : "开卡" }}
            </div></el-col
          >
          <el-col :span="3"
            ><div class="grid-content bg-purple">实际支付金额：</div></el-col
          >
          <el-col :span="5"
            ><div class="grid-content bg-purple-light">
              {{
                orderDetilData.actualPayAmount
                  ? orderDetilData.actualPayAmount
                  : "-"
              }}
            </div></el-col
          >
        </el-row>
        <el-row>
          <el-col :span="3"
            ><div class="grid-content bg-purple">支付方式：</div></el-col
          >
          <el-col :span="5"
            ><div class="grid-content bg-purple-light">
              {{ orderDetilData.payType ? orderDetilData.payType : "-" }}
            </div></el-col
          >
          <el-col :span="3"
            ><div class="grid-content bg-purple">申请支付号：</div></el-col
          >
          <el-col :span="5"
            ><div class="grid-content bg-purple-light">
              {{
                orderDetilData.payReqOrderNumber
                  ? orderDetilData.payReqOrderNumber
                  : "-"
              }}
            </div></el-col
          >
          <el-col :span="3"
            ><div class="grid-content bg-purple">实际支付金额：</div></el-col
          >
          <el-col :span="5"
            ><div class="grid-content bg-purple-light">
              {{
                orderDetilData.actualPayAmount
                  ? orderDetilData.actualPayAmount
                  : "-"
              }}
            </div></el-col
          >
        </el-row>
        <el-row>
          <el-col :span="4"
            ><div class="grid-content bg-purple">
              第三方支付流水号：
            </div></el-col
          >
          <el-col :span="4"
            ><div class="grid-content bg-purple-light">
              {{
                orderDetilData.transactionNumber
                  ? orderDetilData.transactionNumber
                  : "-"
              }}
            </div></el-col
          >
          <el-col :span="3"
            ><div class="grid-content bg-purple">支付状态：</div></el-col
          >
          <el-col :span="5"
            ><div class="grid-content bg-purple-light">
              {{
                orderDetilData.payStatus == "unpaid"
                  ? "待支付"
                  : orderDetilData.payStatus == "haspay"
                  ? "已支付"
                  : orderDetilData.payStatus == "cancelpay"
                  ? "取消支付"
                  : "退卡"
              }}
            </div></el-col
          >
          <el-col :span="3"
            ><div class="grid-content bg-purple">积分金额：</div></el-col
          >
          <el-col :span="5"
            ><div class="grid-content bg-purple-light">
              {{
                orderDetilData.integralAmount
                  ? orderDetilData.integralAmount
                  : "-"
              }}
            </div></el-col
          >
        </el-row>
        <el-row>
          <el-col :span="3"
            ><div class="grid-content bg-purple">预留款金额：</div></el-col
          >
          <el-col :span="5"
            ><div class="grid-content bg-purple-light">
              {{
                orderDetilData.reserveAmount
                  ? orderDetilData.reserveAmount
                  : "-"
              }}
            </div></el-col
          >
          <el-col :span="3"
            ><div class="grid-content bg-purple">金币金额：</div></el-col
          >
          <el-col :span="5"
            ><div class="grid-content bg-purple-light">
              {{ orderDetilData.goldAmount ? orderDetilData.goldAmount : "-" }}
            </div></el-col
          >
          <el-col :span="3"
            ><div class="grid-content bg-purple">抵扣卷金额：</div></el-col
          >
          <el-col :span="5"
            ><div class="grid-content bg-purple-light">
              {{
                orderDetilData.couponAmount ? orderDetilData.couponAmount : "-"
              }}
            </div></el-col
          >
        </el-row>
        <el-row>
          <el-col :span="3"
            ><div class="grid-content bg-purple">退款金额：</div></el-col
          >
          <el-col :span="5"
            ><div class="grid-content bg-purple-light">
              {{
                orderDetilData.refundAmount ? orderDetilData.refundAmount : "-"
              }}
            </div></el-col
          >
          <el-col :span="3"
            ><div class="grid-content bg-purple">创建时间：</div></el-col
          >
          <el-col :span="5"
            ><div class="grid-content bg-purple-light">
              {{
                orderDetilData.orderSource ? orderDetilData.orderSource : "-"
              }}
            </div></el-col
          >
          <el-col :span="3"
            ><div class="grid-content bg-purple">发票号：</div></el-col
          >
          <el-col :span="5"
            ><div class="grid-content bg-purple-light">
              {{
                orderDetilData.invoiceNumber
                  ? orderDetilData.invoiceNumber
                  : "-"
              }}
            </div></el-col
          >
        </el-row>
        <el-row>
          <el-col :span="3"
            ><div class="grid-content bg-purple">备注：</div></el-col
          >
          <el-col :span="5"
            ><div class="grid-content bg-purple-light">
              {{ orderDetilData.remarks ? orderDetilData.remarks : "-" }}
            </div></el-col
          >
        </el-row>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="centerDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="centerDialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 补开发票弹窗 -->
    <!-- 详情页弹窗 -->
    <el-dialog
    id="billdraw"
      title="补开发票"
      :visible.sync="billdrawDialogVisible"
      :close-on-click-modal="false"
      width="40%"
      center
    >
      <el-form
        :model="billdrawData"
        :rules="billdrawDataRules"
        ref="billdrawData"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="发票抬头" prop="custname">
          <el-input v-model="billdrawData.custname"></el-input>
        </el-form-item>
        <el-form-item label="税号">
          <el-input v-model="billdrawData.custtaxno"></el-input>
        </el-form-item>
        <el-form-item label="地址">
          <el-input v-model="billdrawData.custaddress"></el-input>
        </el-form-item>
        <el-form-item label="电话">
          <el-input v-model="billdrawData.custphone"></el-input>
        </el-form-item>
        <el-form-item label="银行账号">
          <el-input v-model="billdrawData.custbankaccount"></el-input>
        </el-form-item>
        <el-form-item label="银行名称">
          <el-input v-model="billdrawData.custbankname"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="billdrawDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitbill('billdrawData')"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "customerOrder",
  data() {
    return {
      // 补开发票弹窗
      billdrawDialogVisible: false,
      // 会员卡详情
      centerDialogVisible: false,
      // 分页
      pageSize: 10,
      currentPage: 1,
      pageTotal: 0,
      // 表格数据
      recordsData: [],
      // 详情数据
      orderDetilData: {},
      // 导出数据
      json_fields: {
        销售员: "employeeName",
        订单号: "orderNum",
        订单创建时间: "createTime",
        订单完成时间: "fulfilTime",
        会员卡号: "cardCode",
        会员姓名: "customerName",
        卡类型: "cardName",
        单价: "cardPrice",
        购买年限: "purchasePeriod",
        应收金额: "amountReceivable",
        预留款: "usedDeposit",
        积分抵现: "usedCredits",
        折扣卷: "usedCoupon",
        实收金额: "usedMoney",
        收款渠道: "payType",
        银行卡号: "creditCard",
        交易流水号: "partyPayNum",
        售卡部门: "employeeDept",
        支付状态: "state",
        订单状态: "orderState",
        订单来源: "sourceway",
      },
      // 查询表单
      form: {
        orderNumber: "",
        payType: "",
        payStatus: "",
        cardHolderPhone: "",
        vipCardNumber: "",
        createDateMin: "",
        createDateMax: "",
        pageNo: "1",
        pageSize: "10",

        // orderNumber: "",
        // orderNumber: "",
        // orderNumber: "",
        // orderNumber: "",
        // cardCode: "",
        // phone: "",
        // auditState: null,
        // payType: "",
        // state: "",
        // createTime: "",
        // createTimeEnd: "",
        // employeeDeptid: null,
        // auditTime: "",
        // auditTimeEnd: "",
      },
      // 部门列表
      departmentData: [],
      // 补开发票数据
      billdrawData: {
        sourceOrderType: "vipCard",
        orderId: "",
        custname: "",
        custtaxno: "",
        custaddress: "",
        custphone: "",
        custbankaccount: "",
        custbankname: "",
      },
      billdrawDataRules: {
        custname: [
          { required: true, message: "请输入发票抬头", trigger: "blur" },
        ],
      },
    };
  },
  components: {},
  //方法集合
  methods: {
    // 详情按钮
    details(row) {
      this.$axios
        .getCardOrderInfo({
          id: row.id,
        })
        .then((res) => {
          if (res.code == "00000") {
            this.orderDetilData = res.data;
            this.centerDialogVisible = !this.centerDialogVisible;
          }
        });
    },
    // 去支付按钮
    gopay() {},
    // 查询按钮
    query() {
      this.getcustomerCardOrderList();
    },
    getcustomerCardOrderList() {
      this.$axios.getCardOrderList(this.form).then((res) => {
        if (res.code == "00000") {
          this.recordsData = res.data.records;
          this.pageTotal = res.data.total;
        }
      });
    },
    // 查询所有部门
    getAllDepartment() {
      this.$axios.getAllDepartment({}).then((res) => {
        if (res.code == "200") {
          this.departmentData = res.data;
          console.log(this.departmentData);
        }
      });
    },
    handleSizeChange(value) {
      this.form.pageSize = value;
      this.getcustomerCardOrderList();
    },
    handleCurrentChange(value) {
      this.form.pageNo = value;
      this.getcustomerCardOrderList();
      // orders = res.data;
    },
    // 补开发票按钮
    billdrawBtn(row) {
      this.billdrawData.custname = "";
      this.billdrawData.custtaxno = "";
      this.billdrawData.custaddress = "";
      this.billdrawData.custphone = "";
      this.billdrawData.custbankaccount = "";
      this.billdrawData.custbankname = "";
      console.log(row);
      this.billdrawData.orderId = row.orderNumber;
      this.billdrawDialogVisible = !this.billdrawDialogVisible;
    },
    // 补开发票
    submitbill(formName) {
      this.showLoading()
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.getinvoiceFPKJ();
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    // 开发票接口
    getinvoiceFPKJ() { 
      this.$axios.getinvoiceFPKJ(this.billdrawData).then((res) => {
        this.closeLoading()
        if (res.code == "00000") {
          this.$message({
            message: res.data.returnMessage,
            type: res.data.openStatus=='invoiceSuccess'? "success":"error",
          });
          this.billdrawDialogVisible = !this.billdrawDialogVisible;
        }
      });
    },
       //跳出
    closeLoading() {
      this.tableLoading.close();
    },
    //进入
    showLoading() {
      this.tableLoading = this.$loading({
        text: "拼命加载数据中", //显示在加载图标下方的加载文案
        spinner: "el-icon-loading", //自定义加载图标类名
        background: "rgba(0, 0, 0, 0.4)", //遮罩层颜色
        target: document.querySelector("#billdraw"), //loadin覆盖的dom元素节点
      });
    },
  },
  created() {
    this.getAllDepartment();
    this.getcustomerCardOrderList();
  },
  mounted() {},
};
</script>
<style scoped>
.customerOrder {
  margin: 20px;
}

.blueBtn {
  font-size: 13px;
  float: right;
  width: 80px;
  height: 26px;
  color: #ffff;
  line-height: 26px;
  text-align: center;
  background-color: #6090ec;
}
.el-row {
  height: 40px;
  line-height: 40px;
}
</style>